﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace MainFrameDesign.Draws
{
    public static class MyDraw
    {
        public static StringFormat TextAlign = new StringFormat();
        static MyDraw() 
        {
            VituralPen.DashStyle = DashStyle.Dash;
            TextAlign.Alignment = StringAlignment.Center;
            TextAlign.LineAlignment = StringAlignment.Center;
        }
        public static Random randomGenerator = new Random();
        public static Color GetRandColor() 
        {
            Color randomColor;
            int R, G, B;
            R = randomGenerator.Next(0, 255);
            G = randomGenerator.Next(0, 255);
            B = randomGenerator.Next(0, 255);
            randomColor = Color.FromArgb(R, G, B);
            return randomColor;
        }
        public static Color ClearColor = ColorTranslator.FromHtml("#F5F5F5");
        public static Pen pen = new Pen(Color.Black, 1);
        public static Font font = new Font("Helvetica Neue", 12);
        public static Color BorderColor = ColorTranslator.FromHtml("#CCC");
        public static Color StringColor = ColorTranslator.FromHtml("#444");
        public static Pen BorderPen = new Pen(BorderColor,1);
        public static Pen StringPen = new Pen(StringColor);
        public static Pen VituralPen = new Pen(Color.Black, 1);
        public static SolidBrush StringBrush = new SolidBrush(StringColor);
        public static Font StringBoldFont = new Font("宋体",10,FontStyle.Bold);
        public static GraphicsPath DrawPath = new GraphicsPath();
        public static SolidBrush PathBrush = new SolidBrush(ColorTranslator.FromHtml("#DDD"));
        public static GraphicsPath CreateRoundedRectanglePath(Rectangle rect)
        {
            int radius = 10;
            DrawPath.Reset();
            DrawPath.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
            DrawPath.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
            DrawPath.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
            DrawPath.AddArc(rect.X, rect.Y + rect.Height - radius, radius, radius, 90, 90);
            DrawPath.CloseAllFigures();
            return DrawPath;
        }

        public static GraphicsPath CreateRoundedRectanglePathHalf(Rectangle rect) 
        {
            int radius = 10;
            DrawPath.Reset();
            DrawPath.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
            DrawPath.AddLine(rect.X + radius, rect.Y, rect.X + rect.Width, rect.Y);
            DrawPath.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
            DrawPath.AddLine(rect.X + rect.Width-radius, rect.Y+rect.Height,rect.X,rect.Y+rect.Height);
            DrawPath.CloseAllFigures();
            return DrawPath;
        }
        /// <summary>
        /// 矩形转String
        /// </summary>
        /// <param name="Rect"></param>
        /// <returns></returns>
        public static string RectToString(Rectangle Rect) 
        {
            return "X:" + Rect.X + " Y:" + Rect.Y + " Width:" + Rect.Width + " Height:" + Rect.Height;
        }
    }
}
